using System.Collections.Specialized;
using System.Net;
using DemoEf;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Quartz;

var builder = WebApplication.CreateBuilder(args);


builder.Configuration

builder.Services.AddQuartz(x =>
{


    // x.Properties["quartz.scheduler.exporter.bindName"] = "Scheduler";
    //     x.Properties["quartz.scheduler.exporter.channelName"] = "tcpQuartz";
    //     x.Properties["quartz.scheduler.exporter.channelType"] = "tcp";
    //     x.Properties["quartz.scheduler.exporter.port"] = "45000";
    //     x.Properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
        x.Properties["quartz.scheduler.instanceName"] =
            Dns.GetHostEntry(Environment.MachineName).HostName.Replace(".", "_");
        x.Properties["quartz.jobStore.type"] = "Quartz.Simpl.RAMJobStore, Quartz";
        x.Properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
     
    
});
builder.Services.AddQuartzServer(x =>
{

    x.StartDelay=TimeSpan.FromSeconds(5);
});


builder.Services.AddSwaggerGen(x =>
{
    
    x.SwaggerDoc("v1",new OpenApiInfo()
    {
        Title = "testapi", Version = "1.0"
    });
});



//builder.Services.AddSpaStaticFiles(x =>
//{
//    x.RootPath = "./wwwroot/nodejs/demo.js";
//});

builder.Services.AddNodeServices(x =>
{

    x.ProjectPath = "testjs";
});

builder.Services.AddDbContext<TestDbContext>(x =>
{
    // x.UseMySql( 
    //     ServerVersion.AutoDetect("Server=192.168.139.122;Port=3306;Database=test;Uid=root;Pwd=root;IgnoreCommandTransaction=true"));
    //

    x.UseMySql(builder.Configuration.GetConnectionString("Default"),ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("Default")));


});
// Add services to the container.
builder.Services.AddRazorPages();

builder.Services.AddMvc();



var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseSwagger().UseSwaggerUI(x => { x.SwaggerEndpoint("/swagger/v1/swagger.json", "API docs"); });

app.UseAuthorization();

app.MapRazorPages();

app.UseEndpoints(x =>
{
    x.MapControllers();
});
app.Run();
